package com.im.partchat.mvp.model.login;

import com.im.partchat.bean.Department;
import com.im.partchat.bean.Group;
import com.im.partchat.bean.User;
import com.im.partchat.bean.UserBean;
import com.im.partchat.bean.reponsed.BaseResponse;
import com.im.partchat.bean.request.ChangePawRequest;
import com.im.partchat.bean.request.GroupSyncRequest;
import com.im.partchat.bean.request.LoginRequest;
import com.im.partchat.bean.request.RequestBean;
import com.im.partchat.bean.request.UserListRequest;
import com.im.partchat.http.service.GroupService;
import com.im.partchat.http.service.UserService;

import java.util.List;

import io.reactivex.Observable;

/**
 * Created by fzl on 2017/6/28 0028.
 * VersionCode: 1
 * Desc:
 */

public class LoginModelImpl implements LoginModel {
    @Override
    public Observable<BaseResponse<UserBean>> login(String userName, String password) {
        RequestBean<LoginRequest> requestBean = new RequestBean<>();
        requestBean.setData(new LoginRequest(userName, password));
        return UserService.login(requestBean);
    }

    @Override
    public Observable<BaseResponse<List<User>>> getUserList(String userId) {
        RequestBean<UserListRequest> requestBean = new RequestBean<>();
        requestBean.setData(new UserListRequest(userId));
        return UserService.getUserList(requestBean);
    }

    @Override
    public Observable<BaseResponse<String>> changePaw(String userId,String oldPassword,String newPassword) {
        RequestBean<ChangePawRequest> requestBean = new RequestBean<>();
        requestBean.setData(new ChangePawRequest(userId,oldPassword,newPassword));
        return UserService.changePaw(requestBean);
    }

    @Override
    public Observable<BaseResponse<List<Department>>> getDepartment() {
        return UserService.getDepartment();
    }

    @Override
    public Observable<BaseResponse<List<Group>>> getGroupList(String userId) {
        RequestBean<GroupSyncRequest> requestBean = new RequestBean<>();
        requestBean.setData(new GroupSyncRequest(userId));
        return GroupService.getGroupList(requestBean);
    }
}
